﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business.Util;
using ZLCMS.Business.DwzFrame;

namespace ZLCMS.Web.SystemManage.Login
{
    public partial class LoginDialog : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);

            if (IsPostBack)
            {
                MemberLogin();
            }
        }

        protected void MemberLogin()
        {
            //Forms身份验证初始化 
            FormsAuthentication.Initialize();

            String md5Code = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5").ToLower();
            ClientScriptManager csm = this.Page.ClientScript;

            //验证用户输入并得到登录用户，txtName是用户名称，txtPassword是登录密码 
            if (Session[GlobalSessionString.UserCheckCode] == null)
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "验证码过期，请重试。", callbackType = "closeCurrent" });
                return;
            }

            if (Session[GlobalSessionString.UserCheckCode].ToString() != logincode.Text.Trim())
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "验证码输入错误，请重试。", callbackType = "closeCurrent" });
                return;
            }

            if (UserKit.UserLogin(txtName.Text.Trim(), md5Code))
            {
                //转发到请求的页面
                _framePage.Alert(new ReturnCode() { statusCode = 200, message = "登录成功。", callbackType = "closeCurrent" });
            }
            else
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "用户名或密码错误！身份验证失败。", callbackType = "closeCurrent" });
            }
        }
    }
}
